<?php
    session_start();
    
	if (isset($_SESSION['username']))
		$login = true;
	else{
		$login = false;
	}
	
	
	function curPageURL() {
         $pageURL = 'http';
         if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
         $pageURL .= "://";
         if ($_SERVER["SERVER_PORT"] != "80") {
          $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
         } else {
          $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
         }
         return $pageURL;
    }

    function getUserNamePage(){
       /* $url = curPageURL();
        $j = -1;
        $sleng = strlen($url);
        for ($i = 0; $i < $sleng; ++$i){
            if ($url[$i] == '?'){
                $j = $i + 1;
            }
        }

        if ($j != -1){
            return substr($url, $j);
        }
        else{
            return "";
        }*/
		$username = $_GET["un"];
		return $username;
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="footoo.css" />
    <link rel="stylesheet" type="text/css" href="ftheader.css" />
    <link rel="stylesheet" type="text/css" href="ftfooter.css" />
    <link rel="stylesheet" type="text/css" href="ftcommoncontent.css" />
	<link rel="stylesheet" type="text/css" href="ftprofmes.css" />
    <script type="text/javascript" src="registrasi.js"></script>
    <script type="text/javascript" src="datetimepicker.js"></script>
    <title>Profile</title>
</head>

<body>
    <div id="headerwrapper">
	<div id = "headerbgfx"></div>
        <div id="footooheader">
            <div id="footoologo">
            	<a href="#"></a>
            </div>
				<?php
					if (!$login)
					{	echo '<div id="loginarea">';
						echo '<form action="php/auth.php" method="post">';
						echo '	<table id="inputLogin">';
						echo '	<tr>';
						echo '		<td class="iltext">Username</td><td><input type="text" name="usr"></td>';
						echo '		</tr><tr>';
						echo '		<td class="iltext">Password</td><td><input type="password" name="pass"></td>';
						echo '	</tr><tr>';
						echo '	<td></td><td><input type="submit" value="login" /></td>';
						echo '	</tr>';
						echo '</table>';
						echo '</form>';
						echo '</div>';
					}
					else
					{
						$username = $_SESSION["username"];
						$path = 'users/'.$username.'/';
				?>
						<div id="logprofpicarea">
						<div id="profpicarea">
							<table class="logouttable"><tr>
							<td class="logouttd">
							<?php
								echo '<h1 class="username">'.$username.'</h1>';
								echo '<br/>'.'15 follower, 22 followee'.'<br/>';
								echo '<a class="logoutButton" href="php/LogOut.php">Log Out</a>'
							?>
							</td>
							<td style="width:80px">
							<?php
								require_once 'php\photo.php';
								$list = photo::getProfPic($username);
								$row = mysql_fetch_array($list);
								if ($row["FileFoto"] == NULL)
									echo '<img id="profpic" src = "'.'images/bg-photo.png'.'"/><br/>';
								else
								{
									echo '<img id="profpic" alt="profpic" src="'.$path.$row["FileFoto"].'" />';
								}
							?>
							</td></tr></table>
						</div>
						</div>
				<?php
					}
				?>
        </div>
        <div id="footoomenu">
            <ul>
                <li><a href="home.php" >Home</a></li>
				<li><a class="current" href="profile.php?<?php echo $_SESSION[username];?>">Profile</a></li>
				<li><a href="wall.php?<?php echo $_SESSION[username];?>">Wall</a>
				<li><a href="fts.php">Photos</a></li>
				<li><a href="message.php">Message</a></li>
            </ul>
        </div>
    </div>
    <div id="headermirror">
    	<div id="searchbox">
            <form action="search.php" method="post">
                <div class="searchbutton">
                    <input id="searchbutton" type="submit" value="" />
                </div>
                <div class="searchtext">
                <input id="searchtext" class="searchtext" type="text" name="search" value="search" onfocus="filledTrue(this.id, 'search')" onblur="filledFalse(this.id, 'search')" />
            	</div>
            </form>		
        </div>
    </div>
    <div id="contentwrapper"><div id="contento">
        <div class="profilecontent">
        <div class="profileinfocontent">
        	<div class="areaavatar">
            	<?php
					$user = getUserNamePage();
	
					$con = mysql_connect("localhost", "progin", "progin");
					if (!$con)
							die('Could not connect: ' . mysql_error());
	
					mysql_select_db("progin", $con);
	
					$hasil = mysql_query("SELECT * FROM user WHERE Username = '$user'", $con);
					$count = 0;
					
					if ($baris = mysql_fetch_array($hasil)){
						if ($baris["Profpic"] == NULL){
                            $gambar = 'images/bg-photo.png';
                        }
                        else{
                            $idgambar = $baris[8];
                            $hasil2 = mysql_query("SELECT * FROM Foto WHERE IDFOTO = $idgambar", $con);
                            if(mysql_num_rows($hasil2)>0){
                                $baris2 = mysql_fetch_row($hasil2);
                                $gambar= 'users/'.$baris2[1].'/'.$baris2[2];
                            }
                        }
						
						echo '<div id="fotopropic">';
                            echo '<img src="'.$gambar.'" alt="Foto Profil disini" id="foto_profil" name="foto_profil"/>';
                        echo '</div>';
						
					}
				?>
            </div>
			<?php
                $user = getUserNamePage();

                $con = mysql_connect("localhost", "progin", "progin");
                if (!$con)
                        die('Could not connect: ' . mysql_error());

                mysql_select_db("progin", $con);

                $hasil = mysql_query("SELECT * FROM user WHERE Username = '$user'", $con);
                $count = 0;

                if(mysql_num_rows($hasil)>0){
                    while ($baris = mysql_fetch_row($hasil)){
                        $nama = $baris[3];
                        $email = $baris[4];
                        $tanggal = $baris[5];

                       
                        echo '<div class="profile_info">';
                            echo '<div>';
                                echo '<label class="profileinfo_label" id="_name">Name</label>';
                                echo '<label class="profileinfo_value" id="name">'.$nama.'</label>';
                            echo '</div>';
                            echo '<div>';
                                echo '<label class="profileinfo_label" id="_email">Email</label>';
                                echo '<label class="profileinfo_value" id="email">'.$email.'</label>';
                            echo '</div>';
                            echo '<div>';
                                echo '<label class="profileinfo_label" id="_tanggal_lahir">Date of Birth</label>';
                                echo '<label class="profileinfo_value" id="tanggal_lahir">'.$tanggal.'</label>';
                            echo '</div>';
                        echo '</div>';
                    }
                }
        ?>
        </div>         
        </div>
    </div></div>
    <div id="footerwrapper">
    	<div id="footer">
            <div id="footerleft"><br/>
            	ft, ft logoes are trademark of ft company. <br/>
            	Copyright 2010 by : <br/>
                13508011 - M. Albadr Lutan Nasution <br/>
                13508019 - Gregorius Ronny Kaluge <br/>
                13508099 - Alwi Alfiansyah Ramdan <br/>
            </div>
            <div id="footermiddle">

            </div>
            <div id="footerright">

            </div>
        </div>
    </div>
</body>
</html>
